let http = require('axios')

module.exports = {
  createMenu: function (accessToken, menu) {
    return new Promise((resolve, reject) => {
      http.post(`https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${accessToken}`, menu || {}).then(res => {
        resolve(res.data)
      })
    })
  },
  getMenu: function (accessToken) {
    return new Promise((resolve, reject) => {
      http.get(`https://api.weixin.qq.com/cgi-bin/menu/get?access_token=${accessToken}`).then(res => {
        resolve(res.data)
      })
    })
  },
  deleteMenu: function (accessToken) {
    return new Promise((resolve, reject) => {
      http.get(`https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=${accessToken}`).then(res => {
        resolve(res.data)
      })
    })
  },
  addConditionnalMenu: function (accessToken, menu) {
    return new Promise((resolve, reject) => {
      http.post(`https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=${accessToken}`, menu || {}).then(res => {
        resolve(res.data)
      })
    })
  },
  deleteConditionalMenu: function (accessToken, menuid) {
    return new Promise((resolve, reject) => {
      http.post(`https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=${accessToken}`, { menuid }).then(res => {
        resolve(res.data)
      })
    })
  },
  testConditionalMenu: function (accessToken, userid) {
    return new Promise((resolve, reject) => {
      http.post(`https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=${accessToken}`, { user_id: userid }).then(res => {
        resolve(res.data)
      })
    })
  }
}
